package com.yaozheng.vocationaltraining.view.collect;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.view.ExamProgressStatusView;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * 我的收藏一项
 */
@EViewGroup(R.layout.item_course_catalog)
public class MyCollectItemView extends LinearLayout {
    @ViewById
    TextView coursewareTitleText;
    @ViewById
    ImageView coursewareImage;

    @ViewById
    ExamProgressStatusView examProgressStatusView;


    public MyCollectItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public MyCollectItemView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public void loadData(int position, JSONObject courseJsonObject,
                         BitmapLoader bitmapLoader) {
        int type = TypeUtils.getJsonInteger(courseJsonObject, "type");
        coursewareTitleText.setText(TypeUtils.getJsonString(courseJsonObject,
                "targetSubject"));
//        if (TypeUtils.getJsonBoolean(courseJsonObject, "learned")) {
//            //复习
//        } else {
////            学习
//        }
        if (type == 2) {
            examProgressStatusView.setVisibility(View.GONE);
        } else {
            examProgressStatusView.getExamProgressButtonStatusView().setInnerCirclePaintColor(Color.parseColor("#3Fe5e5e5"));
            examProgressStatusView.setPaperStatusTypeExplanationTextValue("%");
            examProgressStatusView.setStatus(TypeUtils.getJsonInteger(courseJsonObject, "learnedPercent", 0));
            examProgressStatusView.setTextColorWhite();
            examProgressStatusView.setVisibility(View.VISIBLE);
        }
        loadCoursewareImage(courseJsonObject, bitmapLoader);
    }

    /**
     * 加载图片
     *
     * @param courseJsonObject
     */
    public void loadCoursewareImage(JSONObject courseJsonObject,
                                    BitmapLoader bitmapLoader) {
        bitmapLoader.displayImage(
                TypeUtils.getJsonString(courseJsonObject, "targetImage"),
                coursewareImage);
    }
}
